<template>
  <div class="drowDown" ref="dropDownRef">
    <div class="hasLogin">
      <span @click="clickDrown">
        你好 {{info.name}} 
        <i v-show="showDropDown==false" class="icons fa fa-angle-down"></i>
        <i v-show="showDropDown" class="icons fa fa-angle-up"></i>
      </span> 
      <div :class="!showDropDown?'show':'noshow'" class="drawdown">
        <ul>
          <slot></slot>
        </ul>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import {defineComponent,ref,watch} from 'vue'
import useClickOutside from '../../hooks/isClickOutside'
export default defineComponent({
  components:{
    // dropDownItem
  },
  props:{
    info:{
      type:Object,
      require:true
    }
  },
  setup(){
    const showDropDown = ref(true)
    // Vue3 通过 ref 绑定dom元素是有讲究的 ref名称必须和html中ref值保持一致 且js中ref的初始值必须为null，这样才会指向那个dom元素
    const dropDownRef = ref<null|HTMLElement>(null) 
    const isClickFlag = useClickOutside(dropDownRef)
    const clickDrown = ()=>{
      // alert('hasClick')
      showDropDown.value = !showDropDown.value
    }
    watch(isClickFlag,()=>{
      isClickFlag.value ? showDropDown.value = true : showDropDown.value = false
    })
    return {
      showDropDown,
      clickDrown,
      dropDownRef 
    }
  }
})
</script>

<style lang="less" scoped>
.hasLogin{
  position: relative;
  -webkit-user-select: none;
  >span{
    color: #fff;
    border: 1px solid #fff;
    padding: 10px 15px;
    border-radius: 5px;
    cursor: pointer;
    transition: all ease-in-out .2s;
    &:hover{
      background-color: #fff;
      color:  rgb(64,158,255);
      box-shadow: 0 0 10px #fff;
    }
    .icons{
      margin-left: 5px;
    }
  }
  .drawdown{
    position: absolute;
    border-radius: 5px;
    opacity: 0;
    // height: 100%;
    transition: all ease-in-out .15s;
    width: 120%;
    border: 1px solid #ccc;
    box-shadow: 0 0 5px #ccc;
    background-color: #fff;
    margin-top: 10px;
    padding: 0px 15px;
    padding-top: 5px;
    ul{
      color: rgb(64,158,255);
      li{
        padding: 5px 0;
        cursor: pointer;
        text-decoration: underline;
        text-align: left;
      }
    }
  }
  .show{
    opacity: 1;
  }
}
</style>